<template>
  <div class="bg-light">
    <!-- 头部 -->
    <div class="header d-flex align-items-center">
      <router-link to="/politics" class="text-dark">
        <i class="bi bi-chevron-left fs-4"></i>
      </router-link>
      <h5 class="mb-0 mx-auto">历年真题</h5>
    </div>

    <!-- 年份卡片列表 -->
    <router-link
        v-for="year in yearCards"
        :key="year.gradeLevel"
        :to="`/politics/real/practice?year=${year.gradeLevel}&examPaperId=${year.examPaperId}`"
        class="text-decoration-none"
    >
      <div class="year-card">
        <h6 class="year-title">
          <span>
            <i class="bi bi-calendar-fill"></i>
            {{ year.gradeLevel }}年真题
          </span>
          <span :class="getAccuracyBadgeClass(year.accuracyRate)">
            {{ getAccuracyText(year.accuracyRate) }}
          </span>
        </h6>
        <div class="progress">
          <div
              class="progress-bar"
              :style="`width: ${year.completeRate}%`"
          ></div>
        </div>
        <div class="stats-info">
          <span>已完成{{ year.completeRate === null ? '0' : year.completeRate }}%</span>
          <span>{{ year.numberQuestionsCompleted }}/{{ year.questionTotalNum }}题</span>
        </div>
        <div class="stats-detail">
          <div class="stats-item">
            <div class="stats-value">{{ year.numberQuestionsCompleted }}</div>
            <div class="stats-label">已做题数</div>
          </div>
          <div class="stats-item">
            <div class="stats-value">{{ year.numberCorrectAnswers }}</div>
            <div class="stats-label">答对题数</div>
          </div>
          <div class="stats-item">
            <div class="stats-value">{{ year.numberIncorrectQuestions }}</div>
            <div class="stats-label">错题数</div>

          </div>
          <div class="stats-item">
            <div class="stats-value">{{ year.remainingQuestions }}</div>
            <div class="stats-label">剩余题数</div>
          </div>
        </div>
      </div>
    </router-link>
  </div>
</template>

<script>
import http from '@/router/http';
import router from "@/router/index";
import {paperTypeDict} from "@/router/dict"
export default {
  name: 'PoliticsRealView',
  data() {
    return {
      yearCards: [
        // {
        //   examPaperId: null,
        //   gradeLevel: null,
        //   accuracyRate: null,
        //   completeRate: null,
        //   questionTotalNum: null,
        //   numberQuestionsCompleted: null,
        //   numberCorrectAnswers: null,
        //   numberIncorrectQuestions: null,
        //   remainingQuestions: null
        // }
      ]
    }
  },
  mounted() {
    const paperType = paperTypeDict.find(item => item.label === '历年真题').value;
    http.get('/student/question/getQuestionPoliticsList?paperType='+paperType)
        .then(response => {
          const data = response.data.response;
          data.forEach(item => {
            this.yearCards.push(item);
          });

          // this.yearCards = response.data;
        })
        .catch(error => {
          console.error('获取政治真题数据失败：', error);
          alert('获取政治真题数据失败，请稍后再试');
          router.push('/politics');
        });
  },
  methods: {
    getAccuracyBadgeClass(accuracyRate) {
      if (!accuracyRate) return 'accuracy-badge'
      if (accuracyRate < 70) return 'accuracy-badge low'
      if (accuracyRate < 85) return 'accuracy-badge medium'
      return 'accuracy-badge high'
    },
    getAccuracyText(accuracyRate) {
      if (!accuracyRate){
        return '正确率 0%'
      }else{
        return `正确率 ${accuracyRate}%`
      }
    }
  }
}
</script>

<style scoped>
body {
  background-color: #f0f9f9;
  padding-bottom: 70px;
}

.header {
  padding: 15px;
  background: white;
  position: sticky;
  top: 0;
  z-index: 1000;
}

.year-card {
  background: white;
  margin: 15px;
  padding: 20px;
  border-radius: 15px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.year-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.year-title {
  color: #B19CD9;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.progress {
  height: 6px;
  margin: 15px 0;
}

.progress-bar {
  background-color: #B19CD9;
}

.stats-info {
  display: flex;
  justify-content: space-between;
  color: #666;
  font-size: 0.9rem;
  margin-top: 10px;
}

.stats-detail {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 15px;
  padding-top: 15px;
  border-top: 1px solid #eee;
}

.stats-item {
  text-align: center;
}

.stats-value {
  font-size: 1.2rem;
  color: #B19CD9;
  font-weight: bold;
}

.stats-label {
  font-size: 0.8rem;
  color: #666;
}

.accuracy-badge {
  background: #e9ecef;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.8rem;
}

.accuracy-badge.low {
  background: #FFE4E1;
  color: #dc3545;
}

.accuracy-badge.medium {
  background: #FFF3CD;
  color: #856404;
}

.accuracy-badge.high {
  background: #E8F5E9;
  color: #28a745;
}
</style> 